package com.fr.report.web.ui;

import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.condition.Condition;
import com.fr.data.core.DataXMLUtils;
import com.fr.report.js.JavaScriptImpl;
import com.fr.report.web.event.ActionUtils;
import com.fr.report.web.event.Listener;
import com.fr.web.Repository;

public abstract class ToolBarButton extends Button
{
  protected Condition condition;

  public ToolBarButton(String paramString)
  {
    super(paramString);
    setDisabled(true);
  }

  public ToolBarButton(String paramString1, String paramString2)
  {
    super(paramString1, paramString2);
    setDisabled(true);
  }

  public Condition getCondition()
  {
    return this.condition;
  }

  public void setCondition(Condition paramCondition)
  {
    this.condition = paramCondition;
  }

  public Listener[] createListeners(Repository paramRepository)
  {
    return new Listener[] { new Listener("click", new JavaScriptImpl(clickAction(paramRepository))), new Listener(WebContentUtils.getContentPanel(paramRepository), "startload", new JavaScriptImpl(ActionUtils.getDisableAction())), new Listener(WebContentUtils.getContentPanel(paramRepository), "afterload", new JavaScriptImpl(onContentPanelAfterLoad(paramRepository))) };
  }

  protected abstract String clickAction(Repository paramRepository);

  protected String onContentPanelAfterLoad(Repository paramRepository)
  {
    return ActionUtils.getEnableAction();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if ((paramXMLableReader.isChildNode()) && ("Condition".equals(paramXMLableReader.getTagName())))
      this.condition = DataXMLUtils.readCondition(paramXMLableReader);
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (this.condition != null)
      DataXMLUtils.writeXMLCondition(paramXMLPrintWriter, this.condition);
  }

  public boolean equals(Object paramObject)
  {
    if ((paramObject == null) || (!(paramObject instanceof ToolBarButton)))
      return false;
    return super.equals(paramObject);
  }
}